<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="geometry" content="polygon">
  <link rel="stylesheet" href="./assets/common.css">
  <title>Day/Hour Heatmap</title>
</head>

<body>
  <div id="canvas"></div>
  <script src="./assets/lodash-4.17.4.min.js"></script>
  <script src="./assets/jquery-3.2.1.min.js"></script>
  <script src="./assets/data-set.min.js"></script>
  <script src="../build/g2.js"></script>
  <script>
    $.get('./data/day-hour-heatmap.tsv', data => {
      const ds = new DataSet();
      const dv = ds.createView('demo')
        .source(data, {
          type: 'tsv'
        })
        .transform({
          type: 'map',
          callback(row) {
            row.day = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ][parseInt(row.day - 1, 10)];
            // row.hour = parseInt(row.hour, 10); // keep row.hour as a string
            row.value = parseInt(row.value, 10);
            return row;
          }
        });
      const chart = new G2.Chart({
        container: 'canvas',
        forceFit: true,
        height: window.innerHeight
      });
      chart.source(dv.rows);
      chart.scale({
        day: {
          type: 'cat'
        },
        hour: {
          type: 'cat'
        }
      });
      chart.axis('hour', {
        title: null,
        grid: {
          line: {
            stroke: '#d9d9d9',
            lineWidth: 1,
            lineDash: [ 2, 2 ]
          }
        }
      });
      chart.axis('day', {
        title: null
      });
      chart.polygon()
        .position('hour*day')
        .color('value', '#f6f6f6-#36B3C3');
      chart.render();
    });
  </script>
</body>

</html>
